package servlet.man;

import bean.Result;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author 李夏
 * @version 1.0
 */
//宿管修改学生宿舍(一个楼栋之间)
@WebServlet("/man/changeStuBuild")
public class ChangeStuBuildServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer dorNumber= Integer.valueOf(request.getParameter("dorNumber"));
        Integer buildId= Integer.valueOf(request.getParameter("buildId"));
        Integer stuId= Integer.valueOf(request.getParameter("stuId"));
       Integer data= UserDaoImpl.changeStuBuildByMan(dorNumber,buildId,stuId);
        Result result = new Result();
        if(data!=null){
            result.success(data);
            ObjectMapper objectMapper = new ObjectMapper();
            String str = objectMapper.writeValueAsString(result);
            response.setContentType("application/json;charset=utf8");
            response.getWriter().print(str);


        }else{
            result.fail();
            ObjectMapper objectMapper = new ObjectMapper();
            String str = objectMapper.writeValueAsString(result);
            response.setContentType("application/json;charset=utf8");
            response.getWriter().print(str);


        }

    }
}
